<?php
/*
 * MiniMe - a minimalistic OStatus complient microblogging tool
 * Copyright (C) 2010, Tuomas Koski - koski.tuomas@gmail.com
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * <entry>
 *  <title>Testkoski is testing.</title>
 *  <link rel="alternate" type="text/html" href="http://identi.ca/notice/46665690"/>
 *  <id>http://identi.ca/notice/46665690</id>
 *  <published>2010-08-19T07:44:07+00:00</published>
 *  <updated>2010-08-19T07:44:07+00:00</updated>
 *  <content type="html">Testkoski is testing.</content>
 *  <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
 *  <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
 *  <statusnet:notice_info local_id="46665690" source="web"></statusnet:notice_info>
 *  <link rel="ostatus:conversation" href="http://identi.ca/conversation/46308829"/>
 *  <georss:point>48.8601 2.3507</georss:point>
 * </entry>
 * 
 * @author     Tuomas Koski <koski.tuomas@gmail.com>
 * @copyright  Tuomas Koski
 * @license    http://www.gnu.org/licenses/lgpl.txt
 */
class Mm_Atom_Element_Entry_Builder extends Mm_Xml_Element_Builder_Abstract {
    
    protected $mandatoryChildElements = array(
        array('key' => Mm_Atom_Element_Entry::ELEMENT_TITLE , 'type' => 1, 'builder' => 'Mm_Atom_Element_Title', 'xpath_query' => '/atom:entry/atom:title[1]'),
        array('key' => Mm_Atom_Element_Entry::ELEMENT_ID, 'type' => 1, 'builder' => 'Mm_Atom_Element_Id', 'xpath_query' => '/atom:entry/atom:id[1]'),
        array('key' => Mm_Atom_Element_Entry::ELEMENT_UPDATED, 'type' => 1, 'builder' => 'Mm_Atom_Element_Updated', 'xpath_query' => '/atom:entry/atom:updated[1]'),
        array('key' => Mm_Atom_Element_Entry::ELEMENT_LINK_ALTERNATE, 'type' => 1, 'builder' => 'Mm_Atom_Element_Link', 'xpath_query' => '/atom:entry/atom:link[@rel="alternate"][1]'),
    );
    
    protected $optionalChildElements = array(
        array('key' => Mm_Atom_Element_Entry::ELEMENT_AUTHOR, 'type' => 2, 'builder' => 'Mm_Atom_Element_Author_Builder', 'xpath_query' => '/atom:entry/atom:author[1]'),
        array('key' => Mm_Atom_Element_Entry::ELEMENT_VERB, 'type' => 1, 'builder' => 'Mm_Atom_Element_Activitystream_Verb', 'xpath_query' => '/atom:entry/activity:verb'),
        array('key' => Mm_Atom_Element_Entry::ELEMENT_OBJECT_TYPE, 'type' => 1, 'builder' => 'Mm_Atom_Element_Activitystream_ObjectType', 'xpath_query' => '/atom:entry/activity:object-type'), 
        array('key' => Mm_Atom_Element_Entry::ELEMENT_ACTIVITY_OBJECT, 'type' => 2, 'builder' => 'Mm_Atom_Element_Activitystream_Object_Builder', 'xpath_query' => '/atom:entry/activity:object[1]'),
        array('key' => Mm_Atom_Element_Entry::ELEMENT_ACTIVITY_ACTOR, 'type' => 2, 'builder' => 'Mm_Atom_Element_Activitystream_Actor_Builder', 'xpath_query' => '/atom:entry/activity:actor[1]'),
    );
    
    public function __construct($rawXML) {
        $this->rawXML = $rawXML;
    }
    
    /**
     * @return Mm_Atom_Element_ActivityStream_Subject
     */
    public function build() {
        $this->parseChildElementsFromRawXML();
        return new Mm_Atom_Element_Entry($this->childElements, $this->namespaces);
    }
}